module.exports = {

	get: {
		
		//使用storeId获得商户数据
		'/store/:storeId([a-zA-Z0-9]{10})': async ctx => {
			const {storeId} = ctx.params
			return await ctx.handles.store.getStoreByStoreId(storeId)
		},

		'/store/:codeId([a-zA-Z0-9]{32})': async ctx => {
			const {codeId} = ctx.params
			return await ctx.handles.store.getStoreByCodeId(codeId)
		},

		'/store/:codeId([a-zA-Z0-9]{32})/tableNum': async ctx => {
			const {codeId} = ctx.params
			return await ctx.handles.store.getTableNumByCodeId(codeId)
		},

		'/store/:storeId([a-zA-Z0-9]{10})/comment': async ctx => {
			const {storeId} = ctx.params
			const {index, count} = ctx.getData
			if(count > 50)
				return ctx.error('-2010', 'comment count too much')
			return await ctx.handles.store.getCommentByStoreId(storeId, index, count)
		}

	},

	post: {

		'/store/:storeId([a-zA-Z0-9]{10})/printer': async ctx => {
			const {storeId} = ctx.params
			const {printerName, printerCode, printerKey, printerPhone} = ctx.postData
			const printerId = await ctx.handles.printer.addPrinter(storeId, printerName, printerCode, printerKey, printerPhone)
			return printerId
		},

		'/store/:storeId([a-zA-Z0-9]{10})/food': async ctx => {
			const {storeId} = ctx.params
			const {goodsCategory, goodsName, goodsDescription, goodsSpec, goodsChooseSpec} = ctx.postData
			const goodsId = await ctx.handles.store.addGoods(storeId, goodsCategory, goodsName, goodsDescription, goodsSpec, goodsChooseSpec)
			return goodsId
		}

	}

}